<template>
  <commonformdialog :dialogWidth="'30%'" :isshowDialogs="isshowDialog" :dialogTitle="dialogTitle" @closetextDialog="closeDialog" @confirmbtn="confirmbtn">
    <!-- form表单区域 -->
    <div class="formarea">

      <el-form ref="xlcform" size="medium" :rules="rules" :model="xlcforms" label-width="120px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="结果" prop="status">
            <el-radio-group v-model="xlcforms.status">
              <el-radio :label="1">通过</el-radio>
              <el-radio :label="2">驳回</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="backInfo">
           <el-input type="textarea" v-model="xlcforms.backInfo"   :autosize="{ minRows: 3}"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      </el-form>
    </div>

  </commonformdialog>
</template>

<script>
  //弹窗外壳
  import commonformdialog from '@/components/commondialog/commondialog'


  import {

    schoolteamapproval
  } from '@/api/school'

  import {
    getSessionStorage
  } from '@/utils/accessToken'
  export default {
    data() {
      return {
        id:'',
        //训练场表单,
        xlcforms: {
          status:1,
          backInfo:'',
        },
        rules: {
          status:[{
            required: true,
            trigger: 'change'
          }, ],
          backInfo: [],
        },
        }
    },
    components: {
commonformdialog
    },
    props: {
      //是否显示弹窗
      isshowDialog: {
        type: Boolean,
        default: false,
        required: true,
      },
      //表单的名字
      dialogTitle: {
        type: String,
        default: '机构审核',
        required: true,
      },
      //是编辑还是新增
      formType: {
        type: Number,
        default: 0
      },

    },
    watch:{
      'xlcforms.status':function(val){
        if(val==2){
  console.log(val)
          this.rules.backInfo=[{
            required: true,
            message: '请填写备注',
            trigger: 'change'
          }, ]
         console.log(val,this.rules)
        }else{
        this.rules.backInfo=[]
      }
      }
    },
    methods: {

      closeDialog() {
        //重置表单 关闭弹窗
        this.$refs['xlcform'].resetFields()
        this.selectmapinfo = {}
        this.$emit('closedialog')
      },

      //确认提交表单
      async confirmbtn() {

          this.$refs['xlcform'].validate(async (valid) => {
            if (!valid) return
            // TODO 提交表单
            let {
            status,
            backInfo
            } = this.xlcforms
            let params = {
                status,
                backInfo
            }
            params.id=this.id
              let data = await schoolteamapproval(params)
              if (data.code == '0000') {
                this.$message({
                  type: 'success',
                  message: '审核成功!'
                });
                //清空数据
                this.$refs['xlcform'].resetFields()
              }

            this.$emit('confirm')
          })
      },

    },
    mounted() {
  this.$bus.on("getparamsId",async (val)=>{
        //获取要编辑的id
        console.log(val)
        let id = val
        this.id=id
    });

    },


  }
</script>

<style scoped lang='scss'>
  .formtips {
    font-size: 12px;
    color: rgba(0, 0, 0, 0.4);
    margin-left: 100px;

  }
</style>
